﻿using System.Collections;

namespace Storm.TextEditor.Parser.Objects.Collections
{
	/// <summary>
	/// Represents a list of PatternList.
	/// </summary>
	public sealed class PatternListList
		: IEnumerable
	{
		#region Fields

		private ArrayList groups = new ArrayList();
		private Block     parent = null;

		private bool isKeyword = false;
		private bool isOperator = false;

		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the parent Block of the PatternListList.
		/// </summary>
		public Block Parent
        {
        	get { return parent; }
        	set { parent = value; }
        }

		/// <summary>
		/// Gets or sets whether the PatternListList is a keyword.
		/// </summary>
		public bool IsKeyword
		{
			get { return isKeyword;; }
			set { isKeyword = value; }
		}

		/// <summary>
		/// Gets or sets whether the PatternListList is an operator.
		/// </summary>
		public bool IsOperator
		{
			get { return isOperator; }
			set { isOperator = value; }
		}

        /// <summary>
		/// Gets or sets the PatternList at the given index.
		/// </summary>
		/// <param name="index">Index of the PatternList to get/set.</param>
		/// <returns>PatternList at the given index.</returns>
		public PatternList this[int index]
		{
			get { return groups[index] as PatternList; }
			set { groups[index] = value; }
		}

		/// <summary>
		/// Gets the amount of items in the PatternListList.
		/// </summary>
		public int Count
		{
			get { return groups.Count; }
		}

		#endregion

		#region Methods

		#region Public

		/// <summary>
		/// Returns the IEnumerator of the PatternListList.
		/// </summary>
		/// <returns>The IEnumerator of the PatternListList.</returns>
		public IEnumerator GetEnumerator()
		{
			return groups.GetEnumerator();
		}

		/// <summary>
		/// Adds the given PatternList to the PatternListList.
		/// </summary>
		/// <param name="group">PatternList to add.</param>
		/// <returns>The added PatternList.</returns>
		public PatternList Add(PatternList group)
		{
			groups.Add(group);
			group.Parent = this;
			if (parent != null && parent.Parent != null)
				parent.Parent.ChangeVersion();

			return group;
		}

		/// <summary>
		/// Clears the PatternListList.
		/// </summary>
		public void Clear()
		{
			groups.Clear();
		}

		#endregion

		#endregion

		/// <summary>
		/// Initializes a new instance of PatternListList.
		/// </summary>
		public PatternListList()
		{
		}

		/// <summary>
		/// Initializes a new instance of PatternListList.
		/// </summary>
		/// <param name="parent">Block parent of the PatternListList.</param>
		public PatternListList(Block parent)
		{
			this.parent = parent;
		}
	}
}
